#pragma once

#include "Socket.hpp"

using namespace socket_ddsm;

class IOService
{
public:
    IOService()
    {
    }

    void IOExcute(SockSPtr smsock, const Inet &addr)
    {
        // 长服务
        while (true)
        {
            std::string message;
            int n = smsock->Recv(&message);
            if (n > 0)
            {
                LOG(INFO, "get a message from client: %s ,message is %s\n", addr.UniqueName().c_str(), message.c_str());
                
                //执行cal计算

                std::string result = "cal result";
                
                n = smsock->Send(result);
                if(n < 0)
                {
                    LOG(ERROR,"server send back error\n");
                }
            }
            else if (n == 0)
            {
                LOG(INFO, "client [%s] quit/EOF\n", addr.UniqueName().c_str());
                break;
            }
            else
            {
                LOG(ERROR, "client [%s] read fail!\n", addr.UniqueName().c_str());
                break;
            }
        }
    }

    ~IOService()
    {
    }

private:
};
